package com.edu.medicalpro.kepuyemian;

import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;

public class KepuviewModel extends ViewModel {
    //LiveData两种类型
    //1.LiveData<T> 只读不可修改
    //2.MutableLiveData<T> 可读可写
    private MutableLiveData<String> newstype=new MutableLiveData<>();
    public void setNewstype(String newstype) {
        //setValue() 同步
        //postValue() 异步
        this.newstype.postValue(newstype);
    }
    //LifecycleOwner 生命周期持有者，一般与ViewModel使用同一个组件
//Observer<T> 监听组件用于监听LiveData的数据变化
    public void getNewstype(LifecycleOwner owner , Observer<String> observer) {
         newstype.observe( owner ,observer);
    }
}
